using Altova.TypeInfo;

namespace Altova.Xml
{
	public class XsValidation
	{
		private class LengthFacetCheckHelper
		{
			public static bool IsWhitespace(char c)
			{
				if (c != '\t' && c != '\n' && c != '\r')
				{
					return c == ' ';
				}
				return true;
			}

			public static int ComputeLength(string value, WhitespaceType whitespaceNormalization)
			{
				if (whitespaceNormalization == WhitespaceType.Collapse)
				{
					int num = 0;
					bool flag = false;
					for (int i = 0; i < value.Length; i++)
					{
						if (IsWhitespace(value[i]))
						{
							if (num != 0)
							{
								flag = true;
							}
							continue;
						}
						if (flag)
						{
							num++;
							flag = false;
						}
						num++;
					}
					return num;
				}
				return value.Length;
			}

			public static bool IsEqual(string value, string normalizedCompare, WhitespaceType whitespaceNormalization)
			{
				switch (whitespaceNormalization)
				{
				case WhitespaceType.Collapse:
				{
					bool flag = false;
					bool flag2 = false;
					int i = 0;
					int num3 = 0;
					for (; i < value.Length; i++)
					{
						if (IsWhitespace(value[i]))
						{
							if (flag)
							{
								flag2 = true;
							}
							continue;
						}
						flag = true;
						if (num3 == normalizedCompare.Length)
						{
							return false;
						}
						if (flag2)
						{
							if (normalizedCompare[num3] != ' ')
							{
								return false;
							}
							num3++;
							if (num3 == normalizedCompare.Length)
							{
								return false;
							}
							flag2 = false;
						}
						if (value[i] != normalizedCompare[num3])
						{
							return false;
						}
						num3++;
					}
					return true;
				}
				case WhitespaceType.Replace:
				{
					int num = 0;
					int num2 = 0;
					while (num < value.Length && num2 < normalizedCompare.Length)
					{
						if (IsWhitespace(value[num]))
						{
							if (normalizedCompare[num2] != ' ')
							{
								return false;
							}
						}
						else if (value[num] != normalizedCompare[num2])
						{
							return false;
						}
						num++;
						num2++;
					}
					if (num == value.Length != (num2 == normalizedCompare.Length))
					{
						return false;
					}
					return true;
				}
				default:
					return value == normalizedCompare;
				}
			}
		}

		public class FacetCheck_Success : FacetCheckInterface
		{
			public static FacetCheckResult Check(string s, FacetInfo facet, WhitespaceType whitespace)
			{
				return FacetCheckResult.Success;
			}
		}

		public class FacetCheck_string_length : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.ComputeLength(value, whitespaceNormalization) == facet.intValue)
				{
					return FacetCheckResult.Success;
				}
				return FacetCheckResult.Fail;
			}
		}

		public class FacetCheck_string_minLength : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.ComputeLength(value, whitespaceNormalization) >= facet.intValue)
				{
					return FacetCheckResult.Success;
				}
				return FacetCheckResult.Fail;
			}
		}

		public class FacetCheck_string_maxLength : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.ComputeLength(value, whitespaceNormalization) <= facet.intValue)
				{
					return FacetCheckResult.Success;
				}
				return FacetCheckResult.Fail;
			}
		}

		public class FacetCheck_string_enumeration : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.IsEqual(value, facet.stringValue, whitespaceNormalization))
				{
					return FacetCheckResult.EnumSuccess;
				}
				return FacetCheckResult.EnumFail;
			}
		}

		public class FacetCheck_hexBinary_length : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.ComputeLength(value, whitespaceNormalization) == facet.intValue * 2)
				{
					return FacetCheckResult.Success;
				}
				return FacetCheckResult.Fail;
			}
		}

		public class FacetCheck_hexBinary_minLength : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.ComputeLength(value, whitespaceNormalization) >= facet.intValue * 2)
				{
					return FacetCheckResult.Success;
				}
				return FacetCheckResult.Fail;
			}
		}

		public class FacetCheck_hexBinary_maxLength : FacetCheckInterface
		{
			public static FacetCheckResult Check(string value, FacetInfo facet, WhitespaceType whitespaceNormalization)
			{
				if (LengthFacetCheckHelper.ComputeLength(value, whitespaceNormalization) <= facet.intValue * 2)
				{
					return FacetCheckResult.Success;
				}
				return FacetCheckResult.Fail;
			}
		}

		public static readonly FacetCheckInterface facetCheck_Success = new FacetCheck_Success();

		public static readonly FacetCheckInterface facetCheck_string_length = new FacetCheck_string_length();

		public static readonly FacetCheckInterface facetCheck_string_minLength = new FacetCheck_string_minLength();

		public static readonly FacetCheckInterface facetCheck_string_maxLength = new FacetCheck_string_maxLength();

		public static readonly FacetCheckInterface facetCheck_string_enumeration = new FacetCheck_string_enumeration();

		public static readonly FacetCheckInterface facetCheck_hexBinary_length = new FacetCheck_hexBinary_length();

		public static readonly FacetCheckInterface facetCheck_hexBinary_minLength = new FacetCheck_hexBinary_minLength();

		public static readonly FacetCheckInterface facetCheck_hexBinary_maxLength = new FacetCheck_hexBinary_maxLength();

		public static string ReplaceWhitespace(string input)
		{
			return input;
		}

		public static string CollapseWhitespace(string input)
		{
			return input;
		}

		public static bool Validate(string input, Altova.TypeInfo.TypeInfo info)
		{
			return true;
		}
	}
}
